package edu.ntu.im.p2ptrade.action;

import java.util.LinkedList;

import javax.servlet.http.HttpServletRequest;

import edu.ntu.im.p2ptrade.entity.Item;
import edu.ntu.im.p2ptrade.metadata.MetaDataSearcher;

public class ItemSearching extends AjaxAction {

	@Override
	public AjaxResponse execute(HttpServletRequest request) {
		String action = request.getParameter("action");
		String query_term = request.getParameter("query");
		MetaDataSearcher searcher = new MetaDataSearcher();
		
		if(action.equals("start"))
			if(searcher.getItemMap().get(query_term) == null)
				searcher.search(query_term);
		
		LinkedList<Item> ItemList = searcher.getItemMap().get(query_term);
		return success(ItemList);
	}
}
